/**
 * @brief gmock测试--模拟修改引用参数
 */

#include <gmock/gmock.h>
#include <gtest/gtest.h>

using namespace testing;

class Base {
public:
    virtual ~Base() {}

    int         func1(int& value) { return value + 1; }
    virtual int func2(int& value) { return value + 2; }

    virtual int func3(int& value) = 0;
};

class MockBase : public Base {
public:
    MOCK_METHOD1(func1, int(int&));
    MOCK_METHOD1(func2, int(int&));
    MOCK_METHOD1(func3, int(int&));
};

TEST(MockBase, TestRefArg) {
    MockBase mock;

    EXPECT_CALL(mock, func1(_)).WillOnce(DoAll(SetArgReferee<0>(2), Return(3)));
    int value = 0;
    int ret   = 0;

    ret = mock.func1(value);
    EXPECT_EQ(ret, 3);
    EXPECT_EQ(value, 2);

    EXPECT_CALL(mock, func2(_)).WillOnce(DoAll(SetArgReferee<0>(3), Return(5)));
    ret = mock.func2(value);
    EXPECT_EQ(ret, 5);
    EXPECT_EQ(value, 3);

    EXPECT_CALL(mock, func3(_)).WillOnce(DoAll(SetArgReferee<0>(4), Return(7)));
    ret = mock.func3(value);
    EXPECT_EQ(ret, 7);
    EXPECT_EQ(value, 4);
}